package com.xiaodou.mjf.web.console.basic.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.xiaodou.mjf.application.basic.utils.OperatorUtils;
import com.xiaodou.mjf.entity.basic.Operator;
import com.xiaodou.mjf.infrastructure.common.controller.ApplicationController;

/**
 * 登录处理Controller
 * 
 * @author Rocky
 *
 */
@Controller
public class LoginController extends ApplicationController {

	@RequestMapping(value = "login", method = RequestMethod.GET)
	public String login(HttpServletRequest request) {
		// String path = request.getContextPath();
		// String basePath =
		// request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		if (request.getServerName().indexOf("merchant") > -1) {
			return "merchant_login";
		}

		return "login";
	}

	@RequestMapping(value = "login", method = RequestMethod.POST)
	public String login(@RequestParam("username") String userName, @RequestParam("password") String password, Model model) {
		Operator operator = OperatorUtils.getOperator();
		if (operator.getId() != null) {
			logger.debug("demo: logint err!");
			return "redirect:/";
		}
		model.addAttribute("username", "error");
		logger.debug("demo: login ok");
		return "login";
	}

}
